package cn.melonlib.apis.support.comp.service;

import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ApiRequestRecordScheduledWorker extends ApplicationObjectSupport {

    @Resource
    private ApiRequestRecordService apiRequestRecordService;

    @Scheduled(fixedDelay = 5)
    public void scheduledWorker() throws Exception{
        logger.info("ApiRecord:"+Thread.currentThread().getId());
        synchronized (apiRequestRecordService.getCached()) {
            if(apiRequestRecordService.getCached().size()>0){
                apiRequestRecordService.saveLogs();
            }
            apiRequestRecordService.getCached().wait();
        }
    }
}
